home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
366_01
/
ue311c1.arc
/
BIND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-30
|
23KB
|
1,037 lines
/* This file is for functions having to do with key bindings,
descriptions, help commands and startup file.
written 11-feb-86 by Daniel Lawrence
*/
#include <stdio.h>
#include "estruct.h"
#include "eproto.h"
#include "edef.h"
#include "elang.h"
#include "epath.h"
PASCAL NEAR help(f, n) /* give me some help!!!!
bring up a fake buffer and read the help file
into it with view mode */
int f,n; /* prefix flag and argument */
{
register BUFFER *bp; /* buffer pointer to help */
char *fname; /* file name of help file */
/* first check if we are already here */
bp = bfind("emacs.hlp", FALSE, BFINVS);
if (bp == NULL) {
#if SHARED
strcpy(tname, pathname[1]);
fname = flook(tname, FALSE);
#else
fname = flook(pathname[1], FALSE);
#endif
if (fname == NULL) {
mlwrite(TEXT12);
/* "[Help file is not online]" */
return(FALSE);
}
}
/* split the current window to make room for the help stuff */
if (splitwind(FALSE, 1) == FALSE)
return(FALSE);
if (bp == NULL) {
/* and read the stuff in */
if (getfile(fname, FALSE) == FALSE)
return(FALSE);
} else
swbuffer(bp);
/* make this window in VIEW mode, update all mode lines */
curwp->w_bufp->b_mode |= MDVIEW;
curwp->w_bufp->b_flag |= BFINVS;
upmode();
return(TRUE);
}
PASCAL NEAR deskey(f, n) /* describe the command for a certain key */
int f,n; /* prefix flag and argument */
{
register int c; /* key to describe */
register char *ptr; /* string pointer to scan output strings */
char outseq[NSTRING]; /* output buffer for command sequence */
/* prompt the user to type us a key to describe */
mlwrite(TEXT13);
/* ": describe-key " */
/* get the command sequence to describe
change it to something we can print as well */
cmdstr(c = getckey(FALSE), &outseq[0]);
/* and dump it out */
ostring(outseq);
ostring(" ");
/* find the right ->function */
if ((ptr = getfname(getbind(c))) == NULL)
ptr = "Not Bound";
/* output the command sequence */
ostring(ptr);
return(TRUE);
}
/* bindtokey: add a new key to the key binding table */
PASCAL NEAR bindtokey(f, n)
int f, n; /* command arguments [IGNORED] */
{
register unsigned int c;/* command key to bind */
register int (PASCAL NEAR *kfunc)();/* ptr to the requested function to bind to */
register KEYTAB *ktp; /* pointer into the command table */
register int found; /* matched command flag */
char outseq[80]; /* output buffer for keystroke sequence */
/* prompt the user to type in a key to bind */
/* get the function name to bind it to */
kfunc = getname(TEXT15);
/* ": bind-to-key " */
if (kfunc == NULL) {
mlwrite(TEXT16);
/* "[No such function]" */
return(FALSE);
}
if (clexec == FALSE) {
ostring(" ");
TTflush();
}
/* get the command sequence to bind */
c = getckey((kfunc == meta) || (kfunc == cex) ||
(kfunc == unarg) || (kfunc == ctrlg));
if (clexec == FALSE) {
/* change it to something we can print as well */
cmdstr(c, &outseq[0]);
/* and dump it out */
ostring(outseq);
}
/* if the function is a unique prefix key */
if (kfunc == unarg || kfunc == ctrlg || kfunc == quote) {
/* search for an existing binding for the prefix key */
ktp = &keytab[0];
while (ktp->k_type != BINDNUL) {
if (ktp->k_ptr.fp == kfunc)
unbindchar(ktp->k_code);
++ktp;
}
/* reset the appropriate global prefix variable */
if (kfunc == unarg)
reptc = c;
if (kfunc == ctrlg)
abortc = c;
if (kfunc == quote)
quotec = c;
}
/* search the table to see if it exists */
ktp = &keytab[0];
found = FALSE;
while (ktp->k_type != BINDNUL) {
if (ktp->k_code == c) {
found = TRUE;
break;
}
++ktp;
}
if (found) { /* it exists, just change it then */
ktp->k_ptr.fp = kfunc;
ktp->k_type = BINDFNC;
} else { /* otherwise we need to add it to the end */
/* if we run out of binding room, bitch */
if (ktp >= &keytab[NBINDS]) {
mlwrite(TEXT17);
/* "Binding table FULL!" */
return(FALSE);
}
ktp->k_code = c; /* add keycode */
ktp->k_ptr.fp = kfunc; /* and the function pointer */
ktp->k_type = BINDFNC; /* and the binding type */
++ktp; /* and make sure the next is null */
ktp->k_code = 0;
ktp->k_type = BINDNUL;
ktp->k_ptr.fp = NULL;
}
/* if we have rebound the meta key, make the
search terminator follow it */
if (kfunc == meta)
sterm = c;
return(TRUE);
}
/* macrotokey: Bind a key to a macro in the key binding table */
PASCAL NEAR macrotokey(f, n)
int f, n; /* command arguments [IGNORED] */
{
register unsigned int c;/* command key to bind */
register BUFFER *kmacro;/* ptr to buffer of macro to bind to key */
register KEYTAB *ktp; /* pointer into the command table */
register int found; /* matched command flag */
register int status; /* error return */
char outseq[80]; /* output buffer for keystroke sequence */
char bufn[NBUFN]; /* buffer to hold macro name */
/* get the buffer name to use */
if ((status=mlreply(TEXT215, &bufn[1], NBUFN-2)) != TRUE)
/* ": macro-to-key " */
return(status);
/* build the responce string for later */
strcpy(outseq, TEXT215);
/* ": macro-to-key " */
strcat(outseq, &bufn[1]);
/* translate it to a buffer pointer */
bufn[0] = '[';
strcat(bufn, "]");
if ((kmacro=bfind(bufn, FALSE, 0)) == NULL) {
mlwrite(TEXT130);
/* "Macro not defined"*/
return(FALSE);
}
strcat(outseq, " ");
mlwrite(outseq);
/* get the command sequence to bind */
c = getckey(FALSE);
/* change it to something we can print as well */
cmdstr(c, &outseq[0]);
/* and dump it out */
ostring(outseq);
/* search the table to see if it exists */
ktp = &keytab[0];
found = FALSE;
while (ktp->k_type != BINDNUL) {
if (ktp->k_code == c) {
found = TRUE;
break;
}
++ktp;
}
if (found) { /* it exists, just change it then */
ktp->k_ptr.buf = kmacro;
ktp->k_type = BINDBUF;
} else { /* otherwise we need to add it to the end */
/* if we run out of binding room, bitch */
if (ktp >= &keytab[NBINDS]) {
mlwrite(TEXT17);
/* "Binding table FULL!" */
return(FALSE);
}
ktp->k_code = c; /* add keycode */
ktp->k_ptr.buf = kmacro; /* and the function pointer */
ktp->k_type = BINDBUF; /* and the binding type */
++ktp; /* and make sure the next is null */
ktp->k_code = 0;
ktp->k_type = BINDNUL;
ktp->k_ptr.fp = NULL;
}
return(TRUE);
}
/* unbindkey: delete a key from the key binding table */
PASCAL NEAR unbindkey(f, n)
int f, n; /* command arguments [IGNORED] */
{
register int c; /* command key to unbind */
char outseq[80]; /* output buffer for keystroke sequence */
/* prompt the user to type in a key to unbind */
mlwrite(TEXT18);
/* ": unbind-key " */
/* get the command sequence to unbind */
c = getckey(FALSE); /* get a command sequence */
/* change it to something we can print as well */
cmdstr(c, &outseq[0]);
/* and dump it out */
ostring(outseq);
/* if it isn't bound, bitch */
if (unbindchar(c) == FALSE) {
mlwrite(TEXT19);
/* "[Key not bound]" */
return(FALSE);
}
return(TRUE);
}
PASCAL NEAR unbindchar(c)
int c; /* command key to unbind */
{
register KEYTAB *ktp; /* pointer into the command table */
register KEYTAB *sktp; /* saved pointer into the command table */
register int found; /* matched command flag */
/* search the table to see if the key exists */
ktp = &keytab[0];
found = FALSE;
while (ktp->k_type != BINDNUL) {
if (ktp->k_code == c) {
found = TRUE;
break;
}
++ktp;
}
/* if it isn't bound, bitch */
if (!found)
return(FALSE);
/* save the pointer and scan to the end of the table */
sktp = ktp;
while (ktp->k_type != BINDNUL)
++ktp;
--ktp; /* backup to the last legit entry */
/* copy the last entry to the current one */
sktp->k_code = ktp->k_code;
sktp->k_type = ktp->k_type;
sktp->k_ptr.fp = ktp->k_ptr.fp;
/* null